import java.lang.reflect.Array;
import java.util.Arrays;

public class Test {
    public static int triangleNumber(int[] nums) {
        int n = nums.length;
        int count =0;
        Arrays.sort(nums);
        for(int i = n -1;i>0;i--){
            int left =0 , right = i-1;
            while(left < right ){
                int sum = nums[left] + nums[right];
                if(sum > nums[i]){
                    count += right-left;

                    right--;

                }else{
                    left++;
                }
            }
        }
        return count;


    }
    public static String[] findRelativeRanks(int[] nums) {
        String[] ss = new String[nums.length];
        // write your code here
        for(int i = 0 ; i< nums.length ;i++){
            int tmp = i;
            for(int j = i+1;j<nums.length;j++){
                if(nums[tmp]< nums[j]){
                    tmp = j;
                }

            }
            switch(i){
                case 0:
                    ss[tmp] = "Gold Medal";

                    break;
                case 1:
                    ss[tmp] = "Silver Medal";
                    break;
                case 2:
                    ss[tmp] =  "Bronze Medal";
                    break;
            }

        }


        return ss;
    }
    public static void main(String[] args) {
//        String[] relativeRanks = findRelativeRanks(new int[]{1, 2});
//        for (int i = 0; i < relativeRanks.length; i++) {
//            System.out.println(relativeRanks[i]);
//        }
        System.out.println(triangleNumber(new int[]{2, 2, 3, 4}));
    }
}
